package Code.Day2_20240919.com.dx.day02;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @ClassName StringTest
 * @Description 字符串
 * @Author 12994
 * @Date 2024/9/19 18:50
 * @Version 1.0
 **/
public class StringTest {
    public static void main(String[] args) {
        String filename = "1.jpg";
        System.out.println(filename.substring(filename.lastIndexOf('.') + 1));
        String[] x = filename.split("\\.");
        System.out.println(x[x.length - 1]);

        String a = "6!";
        // 不操作原字符串
        System.out.println(a.concat("aaa"));
        System.out.println(a);

        String b = "112233  ";
        // 包含指定字符个数
        System.out.println(b.split("2").length - 1);
        // 取子字符串，前闭后开，若不写endIndex，则直接从beginIndex开始取到结束
        System.out.println(b.substring(0, 2));
        // 去两端空格
        System.out.println(b.trim());

        StringBuffer str = new StringBuffer("112233  ");
        System.out.println(str.toString());
        // 直接操作原字符串(原内存)
        System.out.println(str.append("666"));
        // 从指定空隙插入，后面顺延
        System.out.println(str.insert(2, "8"));
        // 从指定空隙开始，前闭后开，替换成str，可能会更改字符串长度
        System.out.println(str.replace(0, 2, "999"));


        //
        StringBuffer str1 = new StringBuffer("1234567890");
        for (int i = str1.length(); i > 0; i--) {
            if (i % 3 == 0) {
                str1.insert(i - 2, ",");
            }
        }
        System.out.println(str1);
    }
}
